<?php

namespace App\Http\Services;

use App\Lib\agora;
use Illuminate\Support\Facades\Log;

/**
 * 生成声网token
 *
 * Created on 2021/11/4 14:36
 * @Author <yuxiang.zhu@asiainnovations.net>
 */
class GenerateAgoraTokenServices extends CommonServices
{
    /**
     * 生成声网token
     *
     * Created at 2021/11/4 14:36
     * @Author <yuxiang.zhu@asiainnovations.net>
     * @param mixed $roomId
     * @param mixed $userId
     * @param int $validTimeInSeconds
     * @return string
     */
    public function generateToken($roomId, $userId, int $validTimeInSeconds = 24*3600): string
    {
        try {
            return (new agora())->getToken($roomId, $userId, $validTimeInSeconds);
        } catch (\Throwable $exception) {
            Log::info($exception->getMessage());
            return '';
        }
    }
}